package com.ykdl.member.views;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class DateWheelAdapter extends NumericWheelAdapter {
	private static final int DAY = 24 * 60 * 60 * 1000;
	private static final SimpleDateFormat FORMAT2 = new SimpleDateFormat(
			"M月d日");
	private long mStart;
	private long mEnd;
	private Date mNow;
	private int mDays = 0;
	
	public DateWheelAdapter(long startTime, long endTime) {
		Calendar start = Calendar.getInstance();
		Date date = new Date(startTime);
		start.set(date.getYear() + 1900, date.getMonth(), date.getDate());
		mStart = start.getTimeInMillis();
		Calendar end = Calendar.getInstance();
		date = new Date(endTime);
		end.set(date.getYear() + 1900, date.getMonth(), date.getDate());
		mEnd = end.getTimeInMillis();
		mDays = (int) ((mEnd - mStart) / DAY) + 1;
		mNow = new Date(System.currentTimeMillis());
	}

	@Override
	public int getItemsCount() {
		return mDays;
	}

	@Override
	public String getItem(int index) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTimeInMillis(mStart);
		calendar.add(Calendar.DATE, index);
		if (calendar.get(Calendar.YEAR) == mNow.getYear() + 1900
				&& calendar.get(Calendar.MONTH) == mNow.getMonth()
				&& calendar.get(Calendar.DAY_OF_MONTH) == mNow.getDate()) {
			return "今天";
		}

		return FORMAT2.format(calendar.getTime());
	}

	@Override
	public int getMaximumLength() {
		return 10;
	}
}
